package com.stockz.equity.charting.display.indicator;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.painter.indicator.VolumeIndicatorPainter;
import com.stockz.equity.charting.util.Constant.OVERLAY;
import com.stockz.equity.charting.view.StockChartPanelState;
import com.stockz.equity.indicator.Indicator;
import com.stockz.equity.indicator.volume.PriceRange;
import com.stockz.equity.indicator.volume.VolumeIndicator;
import com.stockz.equity.indicator.volume.VolumeIndicatorConfiguration;
import com.stockz.equity.model.Bar;
import com.stockz.equity.model.Bar.BarValueType;

@Component
public class VolumeIndicatorDisplay extends AbstractDisplayableIndicatorConfiguration {
	
	@Autowired
	private VolumeIndicator volumeIndicator;
	private final String fullName = "Volume Indicator";
	private final String shortName = "VOL";

	@Override
	public Indicator<VolumeIndicatorConfiguration> getIndicator() {
		return volumeIndicator;
	}
	
	@Override
	public BarValueType getBarValueType() {
		return volumeIndicator.getBarValueType();
	}
	
	@Override
	public void setBarValueType(BarValueType barValueType) {
		volumeIndicator.setBarValueType(barValueType);
	}
	
	@Override
	public Object getConfiguration() {
		return volumeIndicator.getIndicatorConfiguration();
	}
	
	@Override
	public String getFullName() {
		return fullName;
	}

	@Override
	public String getShortName() {
		return shortName;
	}

	@Override
	public OVERLAY getOverlay() {
		return OVERLAY.PRICE;
	}

	@Override
	public void refreshValues() {
		
	}

	public List<PriceRange> getPriceRangeList(){
		StockChartPanelState state = getStockChartView().getSelectedStockChart().getStockChartPanel().getStockChartPanelState();
		List<Bar> barList = state.getBarList().subList(state.getStartIndex(), state.getEndIndex());
		return volumeIndicator.getPriceRangeList(barList);
	}
	
	@Override
	public String getDescription() {
		return getShortName()+","+volumeIndicator.getIndicatorConfiguration().getDevisions();
	}

	@Override
	public Class<VolumeIndicatorPainter> getPainterClass() {
		return VolumeIndicatorPainter.class;
	}

	@Override
	public boolean isOverlappable() {
		return false;
	}

}
